//
//  HWTabBarItem.m
//  HWSGW
//
//  Created by avachen on 15/10/31.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "HWTabBarItem.h"

@implementation HWTabBarItem

- (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)name title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self != nil) {
        //1、创建子视图
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 20) / 2, 5, 20, 20)];
        imageView.image = [UIImage imageNamed:name];
        //设置图片适应
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self addSubview:imageView];
        
        //2、创建标题视图
        CGFloat maxY = CGRectGetMaxY(imageView.frame);
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, maxY, frame.size.width, 20)];
        //设置label内容
        titleLabel.text = title;
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:11];
        [self addSubview:titleLabel];
    }
    return self;
}
@end
